
<?php

class Product{
private $storeID,$category,$size,$image,$price,$quantity;
////////////////////////////category
function __construct($storeID=null,$category=null,$size=null,$image=false,$price=null,$quantity=null){
      //set data
      
      $this->setData($storeID,$category,$size,$image,$price,$quantity);
        //connect db
      
       $this->connectDB();
       
     //insert to database
      if($storeID==null) {
          
       }
       else{
                    
           $this->addProduct();
           
       }
    
}
private function setData($storeID,$category,$size,$image,$price,$quantity){
    $this->storeID=$storeID;
    $this->price=$price;
    $this->quantity=$quantity;
    $this->size=$size;
    $this->category=$category;
    if($image!=false){
        include 'imageClass.php';
        $img = new imgUploader();
        $this->image=  $img->UploadPath($image);
    }
 else {
        $this->UploadPath=null;
    }
}
private function connectDB(){
        
      try {
          include'database.php';
     $db_config_file="db_config.php";
     $this->db=new database($db_config_file);
}   
       catch (Exception $ex) {
       $ex->getMessage(); 
}
  
    }
    private function displayProduct($row){
  echo "<div class=show >";
  echo $row['proID'] . " " . $row['stID'];
  echo "<br>";	
  echo "</div>";

}
///////////////////////////////
///////////////////////////// return 



/////////////////////////// return
function getProduct($id){
$sql="select * from product where proID='$id'";
$result=mysql_query($sql);
if($result){
while($row = mysql_fetch_array($result))
  {
   displayProduct($row);
  }
  }
  else{
return false;  
}
}
///////////////////////////////
function getStoreProduct($storeID){
$sql="select * from product where stID='$storeID'";
$result=mysql_query($sql);
if($result){
while($row = mysql_fetch_array($result))
  {
    $this->displayProduct($row);
  }
  }
  else{
return false;  
}
}
//////////////////////////////////////
function getProducts(){
$sql="select * from product";
$result=mysql_query($sql);
while($row = mysql_fetch_array($result))
  {
    $this->displayProduct($row);
  }
}
////////////////////////////////////////

function addProduct(){

$sql="INSERT INTO product (stID,category,size,proImage,price,quantity)
VALUES ('$this->storeID','$this->category','$this->size','$this->image','$this->price','$this->quantity')";

if (!mysql_query($sql))
{
  die('Error:failed to ADD product try another time');
}
echo "proudct ADDED";

}
function displayProductsByCategory($storeID,$cat){
     $sql="select * from product where stID='$storeID' AND category='$cat'";
     $result=mysql_query($sql)   or  die ('error');
	 echo 'sss';
     while($row = mysql_fetch_array($result)) 
    {
         $this->displayProduct($row);
    }
	//header('Location:products.html');
}

 
	/// $ImagePath=uploadPath($Image_Name ,$Image_temp_name);
//if($ImagePath !=false){
	 //addProduct($storeID,$category,$size,$ImagePath,$price,$quantity);
	// header('Location:products.html');
//}
}	


?>

